<?php

namespace app\index\model;

use think\Model;

class Article extends Model
{

    public function getArticleListBycategoryId($map='',$limit = '',$sort = 'weigh',$order = 'desc')
    {   
    	$field = "*";   	
    	$list = $this->field($field)->where($map)->order($sort, $order)->limit($limit)->select();    	
    	return $list;
    }     
  
    public function getNewsByid($id) {
    	$map['id'] = $id;
    	$map['status']= 'normal';
    	$field = "*,
	    		(select cj_category.name from cj_category where cj_category.id=cj_news.category_id LIMIT 1) AS category_name
	    		";
    	$news = db('news')->field($field)->where($map)->find();
    	if(empty($news)){
    		$this->redirect('index/error1');
    	}
    	$label = explode(",", $news['label_ids']); //将字符串转换成数组
    	foreach ($label as $key=>$vo){
    		$map1['id']= $vo;
    		$map1['status']= 'normal';
    		$news['label'][$key] = db('label')->where($map1)->find();
    		 
    	}
    	
    	foreach ($news['label'] as $key=>$vo){   		
    		$news['label'][$key]['color_text'] = getColorText($vo['color']);
    	}
    	
    	return $news;
    }
}
